<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<view class="back iconfont icon-xiangzuo1" @tap="backPage"></view>
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">{{Lang.lang('競猜')}}</view>
			<view class="rule" data-url="/pages/index/ruleV?type=game1_rule" @click="gotopage">{{Lang.lang('規則')}}</view>
		</view>

		<view class="bg_box">
			<image v-if="lang=='tc'" class="bg01" src="../../static/game/game_n_1_tc.png" mode="widthFix"></image>
			<image v-if="lang=='en'" class="bg01" src="../../static/game/game_n_1_en.png" mode="widthFix"></image>
			<view class="page_content">
				<view class="nav">
					<block v-for="(item, index) in game_config" :key="index">
						<view class="menu" :class="index == select ? 'menucolor' : ''" :data-index="index"
							@tap="setNavMenu">{{item.game_time}}</view>
					</block>
				</view>


				<view class="gameplay_content" v-if="gameInfo.is_betting==0">
					<view class="title">YYDZ {{Lang.lang('今日是漲還是跌')}}？</view>
					<view class="text">{{gameInfo.betting_stop_time}}
						{{Lang.lang('截止')}}，<span>{{gameInfo.betting_people_num}}</span>{{Lang.lang('人已參與競猜')}}</view>
					<view class="range_box">
						<view class="menu" :class="select02 == 0 ? 'menucolor02' : ''" data-index="0"
							@tap="setNavMenu02">{{Lang.lang('漲')}}</view>
						<view class="menu" :class="select02 == 1 ? 'menucolor02' : ''" data-index="1"
							@tap="setNavMenu02">{{Lang.lang('跌')}}</view>
						<view class="line"></view>
					</view>
					<view class="menu_box">
						<!-- <view class="reset">清零</view> -->
						<view class="num_box">
							<view class="down iconfont icon-jianhao" @tap="subNumber"></view>
							<view class="num">
								<input type="text" value="" v-model="num" />
								<view class="t">YYDZ</view>
							</view>
							<view class="up iconfont icon-jiahao" @tap="addNumber"></view>
						</view>
						<view class="menu" @click="autoPupu">{{Lang.lang('提交')}}</view>
					</view>
				</view>



				<view class="gameplay_content" v-if="gameInfo.is_betting==1">
					<view class="title">YYDZ {{Lang.lang('今日是漲還是跌')}}？</view>
					<view class="text">{{gameInfo.betting_stop_time}} {{Lang.lang('截止')}}，<span>{{gameInfo.betting_people_num}}</span>{{Lang.lang('人已參與競猜')}}</view>
					<view class="range_box">
						<view class="menu" :class="gameInfo.my_betting_type == 1 ? 'menucolor02' : ''">{{Lang.lang('漲')}}</view>
						<view class="menu" :class="gameInfo.my_betting_type == 2 ? 'menucolor02' : ''">{{Lang.lang('跌')}}</view>
						<view class="line"></view>
					</view>
					<view class="rule">{{Lang.lang('您已投入')}}：<span>{{gameInfo.my_betting_num}}</span>YYDZ{{Lang.lang('競猜，去看看其他競猜吧')}}</view>
				</view>
			</view>
		</view>



		<!-- 输入安全码 -->
		<view class="pupu_box" v-if="pupu" @tap="autoPupu">
			<view class="show_box" @tap.stop="">
				<view class="title">{{Lang.lang('請輸入交易密碼')}}</view>
				<view class="input">
					<input type="password" v-model="pay_password" :placeholder="Lang.lang('請輸入交易密碼')" />
				</view>
				<view class="menu_box">
					<view class="menu" @tap="autoPupu">{{Lang.lang('取消')}}</view>
					<view class="menu" @click="joinGameOne">{{Lang.lang('確定')}}</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				num: 50,
				select: 0,
				select02: -1,
				select03: 0,
				lang: 'en',
				link: '',
				pupu: false,
				scrrol: false,
				info: '',
				pay_password: '',
				game_config: [],
				gameInfo: {}
			}
		},
		onLoad() {

		},
		onShow() {
			let that = this;
			that.lang = uni.getStorageSync('_language');
			that.loadData();
		},
		methods: {
			subNumber() {
				var that = this;
				if (that.num == 1) {
					return false;
				} else {
					that.num = that.num - 1;
				}
			},
			addNumber() {
				var that = this;
				that.num = that.num + 1;
			},
			setNavMenu(e) {
				let that = this;
				let index = e.currentTarget.dataset.index;
				that.select = index;
				that.gameInfo = that.game_config[that.select]
			},
			setNavMenu02(e) {
				let that = this;
				let index = e.currentTarget.dataset.index;
				that.select02 = index;

			},
			loadData() {
				let that = this;
				that.Net._post('api/game/gameOneIndex', {}, res => {
					if (res.code == 200) {
						that.game_config = res.data.game_config
						that.select = res.data.venue
						that.gameInfo = that.game_config[that.select]
					}
				});
			},
			joinGameOne() {
				let that = this;
				that.Net._post('api/game/joinGameOne', {
					num: that.num,
					venue: parseInt(that.select) + 1,
					betting_type: parseInt(that.select02) + 1,
					pay_password: that.pay_password
				}, res => {
					if (res.code == 200) {
						that.pupu = false
						that.Msg.Success(res.msg)
						setTimeout(function() {
							that.loadData()
						}, 500)
					}
				});
			},
			autoPupu() {
				let that = this;
				that.pay_password = '';
				that.pupu = !that.pupu;
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},
		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
	}
</script>

<style>
	.header {
		background-color: transparent !important;
	}

	.header .text {
		text-align: center;
	}

	.scrrolHeader {
		width: 100%;
		background-color: #1A1A1A !important;

	}

	.bg_box {
		width: 100%;
		position: relative;
	}

	.bg_box .bg01 {
		width: 100%;
	}

	.page_content {
		width: 92%;
		position: absolute;
		left: calc(50% - 46%);
		top: 26vh;
	}

	.nav {
		width: 100%;
		background-color: #1A1A1A;
		padding: 1vw;
		border-radius: 3vw;
		display: flex;
		align-items: center;
	}


	.nav .menu {
		flex: 1;
		height: 12vw;
		border-radius: 2vw;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 3.5vw;
		color: #fff;
	}

	.menucolor {
		background-color: #333333 !important;
	}

	.menucolor02 {
		background-color: #0E5DFF !important;
	}

	.gameplay_content {
		widows: 100%;
		background-color: #1A1A1A;
		margin-top: 4%;
		padding: 5vw 4vw;
		border-radius: 3vw;
	}

	.gameplay_content .title {
		font-size: 5vw;
		color: #fff;
		font-weight: bold;
	}

	.gameplay_content .text {
		font-size: 3.5vw;
		color: #999;
		margin-top: 3vw;
	}

	.gameplay_content .text span {
		color: #E92857;
	}

	.gameplay_content .rule {
		font-size: 3.5vw;
		color: #999;
		margin-top: 4vw;
		background-color: #0B0B11;
		padding: 3vw 4vw;
		border-radius: 2vw;
	}

	.gameplay_content .rule span {
		color: #E92857;
	}

	.range_box {
		width: 100%;
		display: flex;
		align-items: center;
		margin-top: 4vw;
		position: relative;
	}

	.range_box .menu {
		flex: 1;
		height: 15vw;

		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 5vw;
		color: #fff;
		font-weight: bold;
		background-color: #333333;
	}

	.range_box .menu:nth-child(1) {
		border-radius: 15vw 0vw 0vw 15vw;
	}

	.range_box .menu:nth-child(2) {
		border-radius: 0 15vw 15vw 0;

	}

	.range_box .line {
		width: 3vw;
		background-color: #1A1A1A;
		height: 100%;
		position: absolute;
		left: calc(50% - 1.5vw);
		top: 0;
		transform: skewX(-10deg);
		/* 沿着X轴倾斜30度 */
		transform-origin: right;
		/* 设置变形的原点在右边 */
	}

	.gameplay_content .menu_box {
		width: 100%;
		margin-top: 4vw;
		display: flex;
		align-items: center;
	}

	.gameplay_content .menu_box .menu {
		width: 22vw;
		height: 10vw;
		border-radius: 10vw;
		color: #fff;
		background-color: #FF295E;
		font-size: 3.6vw;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-left: 4%;
	}

	.gameplay_content .menu_box .reset {
		width: 15vw;
		height: 10vw;
		border-radius: 2vw;
		color: #fff;
		font-size: 3.5vw;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 4%;
		border: 1px solid #333333;
	}

	.gameplay_content .menu_box .num_box {
		flex: 1;
		height: 10vw;
		border: 1px solid #333333;
		border-radius: 2vw;
		display: flex;
		align-items: center;
	}

	.gameplay_content .menu_box .num_box .down {
		font-size: 4vw;
		color: #fff;
		width: 10vw;
		height: 10vw;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.gameplay_content .menu_box .num_box .up {
		font-size: 4vw;
		color: #fff;
		width: 10vw;
		height: 10vw;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.gameplay_content .menu_box .num_box .num {
		flex: 1;
		height: 100%;
		border-left: 1px solid #333;
		border-right: 1px solid #333;
		display: flex;
		align-items: center;
		justify-content: center;
		padding-right: 1vw;
	}

	.gameplay_content .menu_box .num_box .num input {
		flex: 1;
		margin-right: 2vw;
		text-align: right;
		color: #fff;
		font-size: 3.5vw;
	}

	.gameplay_content .menu_box .num_box .num .t {
		font-size: 3vw;
		color: #999999;
	}


	/*  */
	.pupu_box {
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.7);
		position: fixed;
		left: 0;
		top: 0;
		z-index: 999;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.pupu_box .show_box {
		width: 70%;
		background-color: #2B2B2B;
		border-radius: 3vw;
		padding: 5vw 0 0 0;
		position: relative;
	}

	.pupu_box .show_box .title {
		width: 100%;
		text-align: center;
		font-size: 4vw;
		color: #fff;
		font-weight: bold;
		margin-bottom: 5vw;
	}

	.pupu_box .show_box .input {
		width: 84%;
		margin: 0 auto;
		background-color: #222222;
		border-radius: 2vw;
	}

	.pupu_box .show_box .input input {
		width: 100%;
		height: 12vw;
		line-height: 12vw;
		font-size: 3.5vw;
		color: #fff;
		text-align: center;
	}

	.pupu_box .show_box .menu_box {
		width: 100%;
		display: flex;
		align-items: center;
		margin-top: 5vw;
	}

	.pupu_box .show_box .menu_box .menu {
		flex: 1;
		height: 12vw;
		line-height: 12vw;
		font-size: 3.8vw;
		text-align: center;
	}

	.pupu_box .show_box .menu_box .menu:nth-child(1) {
		border-radius: 0 0 0 3vw;
		background-color: #414141;
		color: #fff;

	}

	.pupu_box .show_box .menu_box .menu:nth-child(2) {
		border-radius: 0 0 3vw 0;
		color: #fff;
		background-color: #0155FF;
	}

	/*  */
</style>